package com.ujs.edu.demo.controller;

import com.ujs.edu.demo.config.NeedLogin;
import com.ujs.edu.demo.dao.BcBooksMapper;
import com.ujs.edu.demo.dataobject.BcBooks;
import com.ujs.edu.demo.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

@Controller
public class PublishController {

    @Autowired
    private BcBooksMapper bcBooksMapper;


    @RequestMapping(path = "/publish")
    public ModelAndView publish(){
        ModelAndView view=new ModelAndView();
        view.setViewName("publish");
        return view;
    }

    //商品发布，将数据保存进数据库
    @RequestMapping(path = "/publishBooks")
    @ResponseBody
    public ModelAndView publishBooks(BcBooks bcBooks){
        Result result=new Result();

        int bc=bcBooksMapper.insert(bcBooks);
        System.out.println(bc);
        if (bc==1){
            result.setStatus(1);
            result.setMsg("发布成功");
        }else {
         result.setStatus(0);
         result.setMsg("发布失败");
        }
        ModelAndView view=new ModelAndView();
        view.setViewName("publish.html");
        return view;
    }
}
